// const resolve = require("path").resolve;
const indexRoute = require("./modules/index");
const testRoute = require("./modules/test");
const weatherRoute = require("./modules/weather");
const weatherRoute2 = require("./modules/weather2");
const advRoute = require("./modules/adv");
const calendarRoute = require("./modules/calendar");
const devRoute = require("./modules/tr");
const adminRoute = require("./modules/admin");
const tarckRoute = require("./modules/track");
const initRoute = require("./modules/init");
const path = require("path");

const basrRoute = require("./modules/base");

const BASE_PATH = "/api"; // 路由前缀

function resolve(...args) {
  return path.posix.join(...args);
}

function setupRouter(app) {
  // console.log(BASE_PATH,resolve(BASE_PATH, "init"));
  app.use("/", basrRoute);
  app.use(BASE_PATH, indexRoute);
  app.use(resolve(BASE_PATH, "init"), initRoute);
  // app.use("/api/init", initRoute);
  app.use(resolve(BASE_PATH, "test"), testRoute);
  app.use(resolve(BASE_PATH, "weather"), weatherRoute);
  app.use(resolve(BASE_PATH, "weather2"), weatherRoute2);
  app.use(resolve(BASE_PATH, "adv"), advRoute);
  app.use(resolve(BASE_PATH, "calendar"), calendarRoute);
  app.use(resolve(BASE_PATH, "tr"), devRoute);
  app.use(resolve(BASE_PATH, "admin"), adminRoute);
  app.use(resolve(BASE_PATH, "track"), tarckRoute);
}

module.exports = {
  setupRouter
};
